扩展AbstractTestNGSpringContextTests时,java Autowired spring依赖项在抽象基类中始终为空
我有一个抽象的测试基类,它从AbstractTestNGSpringContextTests
扩展而来:
@ContextConfiguration(locations = { "classpath:spring-test-config.xml" })
@ActiveProfiles(resolver = ActiveProfileResolver.class)
public abstract class BaseTest extends AbstractTestNGSpringContextTests {
@Autowired
private MyActions myActions;
@BeforeSuite(dependsOnMethods = "beforeSuite", alwaysRun = true)
public void beforeUISuite() {
myActions.doSomething();
}
}
以及从BaseTest
扩展的测试类
public class ExampleTest extends BaseTest {
@Test
public void exampleTest( ){
// Do something
}
}
当beforeUISuite
方法运行时,myActions
始终为空。为什么这不是由Spring自动连接的?测试运行时ExampleTest
中的自动连接依赖项设置正确,但当beforeUISuite
执行时,没有任何连接
如果我使myActions
受到保护并注释掉beforeUISuite
,则在测试运行时myActions
被正确实例化。在执行标记为@BeforeSuite
的方法之前,它似乎没有连接
共 (0) 个答案